.PHONY: gomods
gomods: ## Install gomods
	go install github.com/jmank88/gomods@v0.1.5

.PHONY: gomodtidy
gomodtidy: gomods
	gomods tidy

.PHONY: docs
docs:
	go install golang.org/x/pkgsite/cmd/pkgsite@latest
	# http://localhost:8080/pkg/github.com/smartcontractkit/chainlink-common/pkg/
	pkgsite

.PHONY: install-protoc
install-protoc:
	script/install-protoc.sh 29.3 /
	go install google.golang.org/protobuf/cmd/protoc-gen-go@`go list -m -json google.golang.org/protobuf | jq -r .Version`
	go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.5.1

.PHONY: mockery
mockery: $(mockery) ## Install mockery.
	go install github.com/vektra/mockery/v2@v2.53.3

.PHONY: rm-mocked
rm-mocked:
	grep -rl "^// Code generated by mockery" | grep .go$ | xargs -r rm

.PHONY: rm-builders
rm-builders:
	# not sure why, but go.tmpl is matched when run in makefile but not when run in the commandline.
	grep -rl "^// Code generated by github.com/smartcontractkit/chainlink-common/pkg/capabilities/cli" | grep .go$ | grep -v go.tmpl$ | xargs -r rm
	# test wasm file should be removed as well
	rm -f ./pkg/workflows/wasm/host/test/cmd/testmodule.wasm

.PHONY: generate
generate: mockery install-protoc gomods cre-protoc
	export PATH="$(HOME)/.local/bin:$(PATH)"; gomods -go generate -x ./...
	find . -type f -name .mockery.yaml -execdir mockery \; ## Execute mockery for all .mockery.yaml files

.PHONY: cre-protoc
cre-protoc:
	cd pkg/capabilities/v2/protoc && go build -o protoc-gen-cre .

.PHONY: lint-workspace lint
GOLANGCI_LINT_VERSION := 1.64.8
GOLANGCI_LINT_COMMON_OPTS := --max-issues-per-linter 0 --max-same-issues 0
GOLANGCI_LINT_DIRECTORY := ./golangci-lint

lint-workspace:
	@./script/lint.sh $(GOLANGCI_LINT_VERSION) "$(GOLANGCI_LINT_COMMON_OPTS)" $(GOLANGCI_LINT_DIRECTORY)

lint:
	@./script/lint.sh $(GOLANGCI_LINT_VERSION) "$(GOLANGCI_LINT_COMMON_OPTS)" $(GOLANGCI_LINT_DIRECTORY) "--new-from-rev=origin/main"